package org.example.struct.array;

/**
 * @author liyishan
 * @date 2024/9/29 10:04
 * @apiNote
 */

public class Test02073TimeRequiredToBuy {
    public int timeRequiredToBuy(int[] tickets, int k) {
        int n = tickets.length;
        int res = 0;
        for (int i = 0; i < n; i++) {
            if(i <= k){
                res += Math.min(tickets[i], tickets[k]);
            }else{
                res += Math.min(tickets[i], tickets[k] - 1);
            }
        }
        return res;
    }
}
